package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.ProjectInfo;
import com.stylefeng.guns.modular.system.service.IProjectInfoService;

/**
 * 楼盘管理控制器
 *
 * @author leequn
 * @Date 2018-08-02 23:40:36
 */
@Controller
@RequestMapping("/projectInfo")
public class ProjectInfoController extends BaseController {

    private String PREFIX = "/system/projectInfo/";

    @Autowired
    private IProjectInfoService projectInfoService;

    /**
     * 跳转到楼盘管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "projectInfo.html";
    }

    /**
     * 跳转到添加楼盘管理
     */
    @RequestMapping("/projectInfo_add")
    public String projectInfoAdd() {
        return PREFIX + "projectInfo_add.html";
    }

    /**
     * 跳转到修改楼盘管理
     */
    @RequestMapping("/projectInfo_update/{projectInfoId}")
    public String projectInfoUpdate(@PathVariable Integer projectInfoId, Model model) {
        ProjectInfo projectInfo = projectInfoService.selectById(projectInfoId);
        model.addAttribute("item",projectInfo);
        LogObjectHolder.me().set(projectInfo);
        return PREFIX + "projectInfo_edit.html";
    }

    /**
     * 获取楼盘管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return projectInfoService.selectList(null);
    }

    /**
     * 新增楼盘管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ProjectInfo projectInfo) {
        projectInfoService.insert(projectInfo);
        return SUCCESS_TIP;
    }

    /**
     * 删除楼盘管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer projectInfoId) {
        projectInfoService.deleteById(projectInfoId);
        return SUCCESS_TIP;
    }

    /**
     * 修改楼盘管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ProjectInfo projectInfo) {
        projectInfoService.updateById(projectInfo);
        return SUCCESS_TIP;
    }

    /**
     * 楼盘管理详情
     */
    @RequestMapping(value = "/detail/{projectInfoId}")
    @ResponseBody
    public Object detail(@PathVariable("projectInfoId") Integer projectInfoId) {
        return projectInfoService.selectById(projectInfoId);
    }
}
